NoMethodError / undefined method `foobar_path' when using form_for
Posted
by
user1850886
on Stack Overflow
See other posts from Stack Overflow
or by user1850886
Published on 2012-11-25T09:58:56Z
Indexed on
2012/11/25
11:04 UTC
Read the original article
Hit count: 148
ruby-on-rails-3
I'm using form_for to create a chatroom and when I view the page I get the following error:
NoMethodError in Chatrooms#new
undefined method `chatrooms_path' for #<#<Class:0xa862b94>:0xa5307f0>
Here's the code for the view, located in app/views/chatrooms/new.html.erb:
<div class="center">
<%= form_for(@chatroom) do |f| %>
<%=f.text_field :topic%>
<br>
<%=f.submit "Start a discussion", class: "btn btn-large btn-primary"%>
<% end %>
</div>
Here's the relevant controller:
class ChatroomsController < ApplicationController
def new
@chatroom = Chatroom.new
end
def show
@chatroom = Chatroom.find(params[:id])
end
end
If I change the line
<%= form_for(@chatroom) do |f| %>
to
<%= form_for(:chatroom) do |f| %>
it works fine.
I've searched around for similar questions but none of the solutions have worked for me. Help?
© Stack Overflow or respective owner